package dyyx;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J;

public class Hello {
	
	private static final Logger log ;
	
	// private static final Logger log = LoggerFactory.getLogger(Hello.class);


	static{
		
		 //  这样写 OK !!!
		 System.setProperty("logdir", "/Users/dugang/alllog3/");
		 log = LoggerFactory.getLogger(Hello.class);
		 
	}

	
	public static void main(String[] args) throws Exception {
		
		
		// final Logger log = LoggerFactory.getLogger(Hello.class);

		
		// 
		SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
		
		System.out.println("hello");
		
		// logback.xml 配置   logdir 变量取不到值  
		// 在这里写不会生效 ，应为 logback先初始化了
		// System.setProperty("logdir", "/Users/dugang/alllog3/");
		System.setProperty("java.util.logging.config.file", "jdklog.properties");
		
		// System.setProperty 无效 但是 配置jvm参数 则 ok   -Dlogdir=/Users/dugang/alllog2/
			
		System.out.println("env.logdir="+System.getenv("logdir"));
		System.out.println("sys.logdir="+System.getProperty("logdir"));

		String msg = "hello,"+new Date();
		System.out.println(msg);
		
		
		JdkLogUtil.info(msg);
		JclLogUtil.info(msg);
		Log4jUtil.info(msg);
		Log4j2Util.info(msg);
		LogBackUtil.info(msg);
		SysoutUtil.info(msg);
		
		System.out.println("hello2");
		
		
		try{		
			String str = null;
			int len = str.length();	
		}catch(Throwable e){
			log.error(e.getMessage(),e);
		}
		
		
		////// 
		
		try{		
			String str = "a";
			Integer.parseInt(str);
		}catch(NumberFormatException e){
			log.error(e.getMessage(),e);
		}

		try{		
			String str = "a";
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error(e.getMessage(),e);
		}
		
		try{		
			String str = "a";
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error",e);
		}
		
		try{		
			String str = "a";
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error");
		}
		
		String str = "a";
		try{		
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error,str="+str);
		}
		
		str = "a";
		try{		
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error,str=[{}]",str);
		}
		
		str = "a";
		try{		
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error,str=[{}]",str,e);
		}
		
		str = "a";
		try{		
			Integer.parseInt(str);
		}catch(Throwable e){
			log.error("parseInt error,str=[{}]",str,"xxx",e);
		}
		
		
		


	}
}
